-
Notifications
You must be signed in to change notification settings - Fork 25
/
classification.md
1624 lines (737 loc) · 24.8 KB
/
classification.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Classification
Classification is a supervised learning task, in which the training data we feed to the algorithm includes the desired labels. The aim of classification task is to classify each data into the corresponding class. So we have to use dataset with known labels to train a classification model. Then choose one model which has best performance to predict unknown data.
Note:If your task is binary classification, the label must be set to either 0 or 1. All metric values would be calculated from the label 1 by default, such as precision, accurary and so on.
## Table of Contents
- [1. Train-Test Data Preparation](#1.Train-Test-Data-Preparation)
- [2. Missing Value Processing](#2.Missing-Value-Processing)
- [3. Data Processing](#3.Data-Processing)
- [4. Model Selection](#4.Model-Selection)
## 1. Train-Test Data Preparation
After [installing](https://geochemistrypi.readthedocs.io/en/latest/For%20User/Installation%20Manual.html) it, the first step is to run the Geochemistry Pi framework in your terminal application.
In this section, we take the built-in dataset as an example by running:
```bash
geochemistrypi data-mining
```
Alternatively, it is perfectly fine if you would like to use your own dataset like:
```bash
geochemistrypi data-mining --data your_own_data_set.xlsx
```
You can choose the appropriate option based on the program's prompts and press the Enter key to select the default option (inside the parentheses).
```bash
Welcome to Geochemistry π!
Initializing...
No Training Data File Provided!
Built-in Data Loading.
No Application Data File Provided!
Built-in Application Data Loading.
✨ Press Ctrl + C to exit our software at any time.
✨ Input Template [Option1/Option2] (Default Value): Input Value
✨ Use Previous Experiment [y/n] (n):
✨ New Experiment (GeoPi - Rock Classification):
'GeoPi - Rock Classification' is activated.
✨ Run Name (XGBoost Algorithm - Test 1):
(Press Enter key to move forward.)
```
After pressing the Enter key, the program propts the following options to let you ***\*choose the Built-in Training Data\****:
```
-*-*- Built-in Training Data Option-*-*-
1 - Data For Regression
2 - Data For Classification
3 - Data For Clustering
4 - Data For Dimensional Reduction
(User) ➜ @Number: 2
```
Here, we choose *_2 - Data For Classification_* and press the Enter key to move forward.
Now, you should see the output below on your screen:
```bash
Successfully loading the built-in training data set
'Data_Classification.xlsx'.
--------------------
Index - Column Name
1 - CITATION
2 - SAMPLE NAME
3 - Label
4 - Notes
5 - LATITUDE
6 - LONGITUDE
7 - Unnamed: 6
8 - SIO2(WT%)
9 - TIO2(WT%)
10 - AL2O3(WT%)
11 - CR2O3(WT%)
12 - FEOT(WT%)
13 - CAO(WT%)
14 - MGO(WT%)
15 - MNO(WT%)
16 - NA2O(WT%)
--------------------
(Press Enter key to move forward.)
```
We hit Enter key to keep moving.
Then, we choose *_2 - Data For Classification_* as our ***\*Built-in Application Data\****:
```bash
-*-*- Built-in Application Data Option-*-*-
1 - Data For Regression
2 - Data For Classification
3 - Data For Clustering
4 - Data For Dimensional Reduction
(User) ➜ @Number: 2
```
After this, the program will display a list for Column Name:
```bash
Successfully loading the built-in inference data set
'InferenceData_Classification.xlsx'.
--------------------
Index - Column Name
1 - CITATION
2 - SAMPLE NAME
3 - Label
4 - Notes
5 - LATITUDE
6 - LONGITUDE
7 - Unnamed: 6
8 - SIO2(WT%)
9 - TIO2(WT%)
10 - AL2O3(WT%)
11 - CR2O3(WT%)
12 - FEOT(WT%)
13 - CAO(WT%)
14 - MGO(WT%)
15 - MNO(WT%)
16 - NA2O(WT%)
17 - Unnamed: 16
18 - SC(PPM)
19 - TI(PPM)
20 - V(PPM)
21 - CR(PPM)
22 - NI(PPM)
23 - RB(PPM)
24 - SR(PPM)
25 - Y(PPM)
26 - ZR(PPM)
27 - NB(PPM)
28 - BA(PPM)
29 - LA(PPM)
30 - CE(PPM)
31 - PR(PPM)
32 - ND(PPM)
33 - SM(PPM)
34 - EU(PPM)
35 - GD(PPM)
36 - TB(PPM)
37 - DY(PPM)
38 - HO(PPM)
39 - ER(PPM)
40 - TM(PPM)
41 - YB(PPM)
42 - LU(PPM)
43 - HF(PPM)
44 - TA(PPM)
45 - PB(PPM)
46 - TH(PPM)
47 - U(PPM)
--------------------
(Press Enter key to move forward.)
```
After pressing the Enter key, you can choose whether you need a world map projection for a specific element option:
```bash
-*-*- World Map Projection -*-*-
World Map Projection for A Specific Element Option:
1 - Yes
2 - No
(Plot) ➜ @Number:
```
More information of the map projection can be found in the section of [World Map Projection](https://geochemistrypi.readthedocs.io/en/latest/For%20User/Model%20Example/Data_Preprocessing/Data%20Preprocessing.html#world-map-projection). In this tutorial, we skip it by typing **2** and pressing the Enter key.
Based on the output prompted, we include column 3 (Label) because it represents the classification label. In a classification task, our goal is to predict or classify data points into specific categories or classes, and the "Label" column contains the information that we want to predict or classify. Then, we also include column 8, 9, 10, 11, 12, 13 (i.e. [8, 13]) in our example.
```bash
-*-*- Data Selection -*-*-
--------------------
Index - Column Name
1 - CITATION
2 - SAMPLE NAME
3 - Label
4 - Notes
5 - LATITUDE
6 - LONGITUDE
7 - Unnamed: 6
8 - SIO2(WT%)
9 - TIO2(WT%)
10 - AL2O3(WT%)
11 - CR2O3(WT%)
12 - FEOT(WT%)
13 - CAO(WT%)
14 - MGO(WT%)
15 - MNO(WT%)
16 - NA2O(WT%)
--------------------
Select the data range you want to process.
Input format:
Format 1: "[**, **]; **; [**, **]", such as "[1, 3]; 7; [10, 13]" --> you want to deal with the columns 1, 2, 3, 7, 10, 11, 12, 13
Format 2: "xx", such as "7" --> you want to deal with the columns 7
@input: 3; [8, 13]
```
Have a double-check on your selection and press Enter to move forward:
```
--------------------
Index - Column Name
3 - Label
8 - SIO2(WT%)
9 - TIO2(WT%)
10 - AL2O3(WT%)
11 - CR2O3(WT%)
12 - FEOT(WT%)
13 - CAO(WT%)
--------------------
(Press Enter key to move forward.)
```
```
The Selected Data Set:
Label SIO2(WT%) ... FEOT(WT%) CAO(WT%)
0 1 53.640000 ... 11.130000 20.240000
1 1 52.740000 ... 12.140000 20.480000
2 1 51.710000 ... 6.850000 22.420000
3 1 50.870000 ... 7.530000 22.450000
4 1 50.920000 ... 6.930000 22.620000
... ... ... ... ... ...
2006 0 52.628866 ... 2.202400 21.172240
2007 0 52.535656 ... 2.093113 21.150105
2008 0 52.163411 ... 2.202465 21.600643
2009 0 44.940000 ... 6.910000 22.520000
2010 0 46.750000 ... 7.550000 22.540000
[2011 rows x 7 columns]
(Press Enter key to move forward.)
```
Now, you should see
```
-*-*- Basic Statistical Information -*-*-
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2011 entries, 0 to 2010
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Label 2011 non-null int64
1 SIO2(WT%) 2010 non-null float64
2 TIO2(WT%) 2010 non-null float64
3 AL2O3(WT%) 2010 non-null float64
4 CR2O3(WT%) 2011 non-null float64
5 FEOT(WT%) 2011 non-null float64
6 CAO(WT%) 2011 non-null float64
dtypes: float64(6), int64(1)
memory usage: 110.1 KB
None
Some basic statistic information of the designated data set:
Label SIO2(WT%) ... FEOT(WT%) CAO(WT%)
count 2011.00000 2010.000000 ... 2011.000000 2011.000000
mean 0.73446 52.110238 ... 3.215889 21.442025
std 0.44173 2.113287 ... 1.496576 2.325046
min 0.00000 0.218000 ... 1.281000 0.097000
25% 0.00000 51.350135 ... 2.535429 20.532909
50% 1.00000 52.200000 ... 2.920000 21.600000
75% 1.00000 52.980000 ... 3.334500 22.421935
max 1.00000 56.301066 ... 18.270000 26.090000
[8 rows x 7 columns]
Successfully calculate the pair-wise correlation coefficient among
the selected columns.
Save figure 'Correlation Plot' in
/Users/lcthw/geopi/geopi_output/GeoPi - Rock
Classification/XGBoost Algorithm - Test
1/artifacts/image/statistic.
Successfully...
Successfully...
...
Successfully store 'Data Selected' in 'Data Selected.xlsx' in
/Users/lcthw/geopi/geopi_output/GeoPi - Rock
Classification/XGBoost Algorithm - Test 1/artifacts/data.
(Press Enter key to move forward.)
```
You should now see a lot of output on your screen, but don't panic.
This output just provides basic statistical information about the dataset, including count, mean, standard deviation, and percentiles for the data column labeled "Label." It also documents the successful execution of tasks such as calculating correlations, drawing distribution plots, and saving generated charts and data files.
Now, let's press the Enter key to proceed.
```
-*-*- Missing Value Check -*-*-
Check which column has null values:
--------------------
Label False
SIO2(WT%) True
TIO2(WT%) True
AL2O3(WT%) True
CR2O3(WT%) False
FEOT(WT%) False
CAO(WT%) False
dtype: bool
--------------------
The ratio of the null values in each column:
--------------------
SIO2(WT%) 0.000497
TIO2(WT%) 0.000497
AL2O3(WT%) 0.000497
Label 0.000000
CR2O3(WT%) 0.000000
FEOT(WT%) 0.000000
CAO(WT%) 0.000000
dtype: float64
--------------------
Note: you'd better use imputation techniques to deal with the
missing values.
(Press Enter key to move forward.)
```
## 2. Missing Value Processing
Now, the program will ask us if we want to deal with the missing values, we can choose **yes** here:
```bash
-*-*- Missing Values Process -*-*-
Do you want to deal with the missing values?
1 - Yes
2 - No
(Data) ➜ @Number: 1
```
For strategy, we choose **2 - Impute Missing Values**:
```bash
-*-*- Strategy for Missing Values -*-*-
1 - Drop Rows with Missing Values
2 - Impute Missing Values
Notice: Drop the rows with missing values may lead to a
significant loss of data if too many features are chosen.
Which strategy do you want to apply?
(Data) ➜ @Number: 2
```
Based on the propt, we choose the **1 - Mean Value** in this example and the input data be processed automatically as:
```
-*-*- Imputation Method Option -*-*-
1 - Mean Value
2 - Median Value
3 - Most Frequent Value
4 - Constant(Specified Value)
Which method do you want to apply?
(Data) ➜ @Number: 1
Successfully fill the missing values with the mean value of each
feature column respectively.
(Press Enter key to move forward.)
```
```bash
-*-*- Hypothesis Testing on Imputation Method -*-*-
Null Hypothesis: The distributions of the data set before and
after imputing remain the same.
Thoughts: Check which column rejects null hypothesis.
Statistics Test Method: Kruskal Test
Significance Level: 0.05
The number of iterations of Monte Carlo simulation: 100
The size of the sample for each iteration (half of the whole data
set): 1005
Average p-value:
Label 1.0
SIO2(WT%) 0.9993660077630827
TIO2(WT%) 0.9966146379846705
AL2O3(WT%) 0.9981857963077964
CR2O3(WT%) 1.0
FEOT(WT%) 1.0
CAO(WT%) 1.0
Note: 'p-value < 0.05' means imputation method doesn't apply to
that column.
The columns which rejects null hypothesis: None
Successfully draw the respective probability plot (origin vs.
impute) of the selected columns
Save figure 'Probability Plot' in
/Users/lcthw/geopi/geopi_output/GeoPi - Rock
Classification/XGBoost Algorithm - Test
1/artifacts/image/statistic.
Successfully store 'Probability Plot' in 'Probability Plot.xlsx'
in /Users/lcthw/geopi/geopi_output/GeoPi - Rock
Classification/XGBoost Algorithm - Test
1/artifacts/image/statistic.
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2011 entries, 0 to 2010
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Label 2011 non-null float64
1 SIO2(WT%) 2011 non-null float64
2 TIO2(WT%) 2011 non-null float64
3 AL2O3(WT%) 2011 non-null float64
4 CR2O3(WT%) 2011 non-null float64
5 FEOT(WT%) 2011 non-null float64
6 CAO(WT%) 2011 non-null float64
dtypes: float64(7)
memory usage: 110.1 KB
None
Some basic statistic information of the designated data set:
Label SIO2(WT%) ... FEOT(WT%) CAO(WT%)
count 2011.00000 2011.000000 ... 2011.000000 2011.000000
mean 0.73446 52.110238 ... 3.215889 21.442025
std 0.44173 2.112761 ... 1.496576 2.325046
min 0.00000 0.218000 ... 1.281000 0.097000
25% 0.00000 51.350271 ... 2.535429 20.532909
50% 1.00000 52.200000 ... 2.920000 21.600000
75% 1.00000 52.980000 ... 3.334500 22.421935
max 1.00000 56.301066 ... 18.270000 26.090000
[8 rows x 7 columns]
Successfully store 'Data Selected Dropped-Imputed' in 'Data
Selected Dropped-Imputed.xlsx' in
/Users/lcthw/geopi/geopi_output/GeoPi - Rock
Classification/XGBoost Algorithm - Test 1/artifacts/data.
(Press Enter key to move forward.)
```
The next step is to select your feature engineering options, for simplicity, we omit the specific operations here. For detailed instructions, please see [here](https://geochemistrypi.readthedocs.io/en/latest/For%20User/Model%20Example/Decomposition/decomposition.html#id6).
```bash
-*-*- Feature Engineering -*-*-
The Selected Data Set:
--------------------
Index - Column Name
1 - Label
2 - SIO2(WT%)
3 - TIO2(WT%)
4 - AL2O3(WT%)
5 - CR2O3(WT%)
6 - FEOT(WT%)
7 - CAO(WT%)
--------------------
Feature Engineering Option:
1 - Yes
2 - No
(Data) ➜ @Number: 2
Successfully store 'Data Selected Dropped-Imputed
Feature-Engineering' in 'Data Selected Dropped-Imputed
Feature-Engineering.xlsx' in /Users/lcthw/geopi/geopi_output/GeoPi
- Rock Classification/XGBoost Algorithm - Test 1/artifacts/data.
(Press Enter key to move forward.)
```
## 3. Data Processing
We select **2 - Classification** as our model:
```bash
-*-*- Mode Selection -*-*-
1 - Regression
2 - Classification
3 - Clustering
4 - Dimensional Reduction
(Model) ➜ @Number: 2
(Press Enter key to move forward.)
```
Before we start the classfication model training, we have to specify our X and Y data set. in the example of our selected data set, we take column [2,7] as our X set and column 1 as Y.
```bash
-*-*- Data Segmentation - X Set and Y Set -*-*-
Divide the processing data set into X (feature value) and Y
(target value) respectively.
Selected sub data set to create X data set:
--------------------
Index - Column Name
1 - Label
2 - SIO2(WT%)
3 - TIO2(WT%)
4 - AL2O3(WT%)
5 - CR2O3(WT%)
6 - FEOT(WT%)
7 - CAO(WT%)
--------------------
The selected X data set:
Select the data range you want to process.
Input format:
Format 1: "[**, **]; **; [**, **]", such as "[1, 3]; 7; [10, 13]" --> you want to deal with the columns 1, 2, 3, 7, 10, 11, 12, 13
Format 2: "xx", such as "7" --> you want to deal with the columns 7
@input: [2, 7]
```
```bash
--------------------
Index - Column Name
2 - SIO2(WT%)
3 - TIO2(WT%)
4 - AL2O3(WT%)
5 - CR2O3(WT%)
6 - FEOT(WT%)
7 - CAO(WT%)
--------------------
Successfully create X data set.
The Selected Data Set:
SIO2(WT%) TIO2(WT%) ... FEOT(WT%) CAO(WT%)
0 53.640000 0.400000 ... 11.130000 20.240000
1 52.740000 0.386000 ... 12.140000 20.480000
2 51.710000 0.730000 ... 6.850000 22.420000
3 50.870000 0.780000 ... 7.530000 22.450000
4 50.920000 0.710000 ... 6.930000 22.620000